# Contributor: John Proctor <jproctor@prium.net>
# Contributor: Alain Kalker <a.c.kalker@gmail.com>
# Maintainer: Juergen Hoetzel <juergen@archlinux.org>

pkgname=cmucl
pkgver=21d
pkgrel=1
pkgdesc="CMU Common Lisp"
depends_i686=('glibc' 'openmotif')
depends_x86_64=('lib32-glibc' 'openmotif')
provides=('common-lisp')
makedepends=('sed' 'bc' 'lib32-gcc-libs')
license=('custom')
#license PublicDomain
source=("https://common-lisp.net/project/cmucl/downloads/release/${pkgver}/cmucl-src-${pkgver}.tar.bz2"
        "https://common-lisp.net/project/cmucl/downloads/release/${pkgver}/cmucl-src-${pkgver}.tar.bz2.asc"
        "https://common-lisp.net/project/cmucl/downloads/release/${pkgver}/cmucl-${pkgver}-x86-linux.tar.bz2"
        "https://common-lisp.net/project/cmucl/downloads/release/${pkgver}/cmucl-${pkgver}-x86-linux.tar.bz2.asc"
	'0001-Fix-68-Use-O1-when-compiling-with-gcc-now.patch'
        'glibc-2.34.patch')
sha256sums=('657d9332ef0453a513a55c4ed84993ac5157e215efa423d2d7aa432a4bbc4ab4'
            'SKIP'
            '45d72d72a3d3b5087561bdc1ae943c8ed445427f3939cc0eb7597dd07eb10d9b'
            'SKIP'
            '48ef3fd1038cc0c53c4a5151f5a3eccde1ac58cef28f4dfc8553b5f7977ea9c9'
            'b3561f995cd5d8ec272883646ef88c44b6f2e27cfcf0b93aad38cf7201b01eac')
validpgpkeys=('0EF50ED55514BFF6B72B9DAC06CE3819086C750B') # "Raymond Toy <toy.raymond@gmail.com>
url="https://www.cons.org/cmucl/"
arch=('loong64' 'x86_64')

prepare() {
  patch -p1 -d "${srcdir}" -i "${srcdir}/0001-Fix-68-Use-O1-when-compiling-with-gcc-now.patch"
  patch -d src -p1 -i ../glibc-2.34.patch # Fix build with glibc 2.34
  if [[ $CARCH == "i686" ]]; then
    sed -i 's|i386\*|i686\*|' "${srcdir}"/bin/build-all.sh
  fi
}

build() {
  cd "${srcdir}"
  export CMUCLLIB="${srcdir}"/lib/cmucl/lib
  # Build using binary-dist lisp
  ./bin/build-all.sh -o "${srcdir}"/bin/lisp -C x86_linux
}

package() {
  cd "${srcdir}"
  # install distribution
  ./bin/make-dist.sh -I "${pkgdir}"/usr -M share/man/man1 -V ${pkgver} linux-4
  # move docs
  mv "${pkgdir}"/usr/doc "${pkgdir}"/usr/share/
  # backwards compatibility
  ln -sf lisp "${pkgdir}"/usr/bin/cmucl
  # license
  install -D -m644 "${srcdir}"/src/general-info/COPYRIGHTS \
                   "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}

